﻿namespace Resonator.Tests
{
	using System.Data;
	using NHibernate.Connection;

	public class SingleConnectionProvider : DriverConnectionProvider
	{
		private static readonly object _syncRoot = new object();
		private static IDbConnection _connection;

		public override IDbConnection GetConnection()
		{
			if (_connection == null)
			{
				lock (_syncRoot)
				{
					if (_connection == null)
					{
						_connection = base.GetConnection();
					}
				}
			}

			return _connection;
		}

		public override void CloseConnection(IDbConnection conn)
		{
		}
	}
}
